package com.cryptooj.project.model.enums;

import org.apache.commons.lang3.ObjectUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 *  题目提交中的编程语言
 * */
public enum QuestionSubmitLanguageEnum {

    JAVA("java","java"),
    CPLUSPLUS("cpp","cpp"),
    GOLAND("go","go"),
    PYTHON("python","python"),
    JAVASCRIPT("javascript","javascript"),
    HTML("html","html");

    private final String text;

    private final String value;

    QuestionSubmitLanguageEnum(final String text, final String value) {
        this.text = text;
        this.value = value;
    }

    public List<String> getValues(){
        return Arrays.stream(values())
                .map(item -> item.value)
                .collect(Collectors.toList());
    }

    public static QuestionSubmitLanguageEnum getEnumByValue(String value){
        if(ObjectUtils.isEmpty(value)){
            return null;
        }
        for(QuestionSubmitLanguageEnum item : QuestionSubmitLanguageEnum.values()){
            if(item.value.equals(value)){
                return item;
            }
        }
        return null;
    }


    public String getText() {
        return text;
    }
    public String getValue() {
        return value;
    }
}
